<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Helpers/PathHelper.php';
  require_once '../../Controllers/UserController.php';
  //
  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //
  require_once '../../Controllers/AdminController.php';
  require_once '../../Controllers/StudentController.php';
  require_once '../../Controllers/SchoolController.php';
  require_once '../../Controllers/EnrolmentController.php';
  //
	  $a = new AdminController();
    $yearLevelPreElem = $a->getYearLevelByDepartment(SchoolController::PRE_ELEMENTARY);
    //
	  $s = new StudentController();
	  $id = $_GET['id'];
	  $st = $s->read($id);
    //Process this area if the user has submitted the form for updates.
    if(isset($_POST) && !empty($_POST))
	  {
	    //Update student record.
      $c = new EnrolmentController();
      $message = $c->enrol(EnrolmentController::UPDATE);
  	  $st = $s->read($id);
	  }
	  //
	  $aStudent = mysql_fetch_assoc($st);
      //
	    $id = $aStudent['StudentId'];
	    $year = $aStudent['SchoolYear'];
	    $departmentId = $aStudent['DepartmentId'];
      $gradeLevel = $aStudent['GradeLevel'];
      $status = $aStudent['Status'];
	    //
	    $name = $aStudent['Name'];
	    $birthDate = $aStudent['BirthDate'];
	    $nickname = $aStudent['Nickname'];
	    $age = $aStudent['Age'];
	    $phoneNum = $aStudent['HomeNumber'];
	    $addr = $aStudent['Address'];
	    $religion = $aStudent['Religion'];
	    $nationality = $aStudent['Nationality'];
	    $gender = $aStudent['Sex'];
	    $schoolAttended = $aStudent['SchoolAttended'];
	    $schoolAttendedYr = $aStudent['SchoolYearAttended'];
      //
      $livesWith = $aStudent['LivesWith'];
      $livesWithSpecify = $aStudent['LivesWithSpecify'];
      //
      $father =  $aStudent['FathersName'];
      $fathersCel = $aStudent['FathersCellphone'];
      $fathersOccupation = $aStudent['FathersOccupation'];
      $fathersOfficePhone = $aStudent['FathersOfficeNumber'];
      $mother = $aStudent['MothersName'];
      $mothersCel = $aStudent['MothersCellphone'];
      $mothersOccupation = $aStudent['MothersCellphone'];
      $mothersOfficePhone = $aStudent['MothersOfficeNumber'];
      //
      $emergencyGuardianName1 = $aStudent['EmergencyGuardianName1'];
      $emergencyGuardianCel1 = $aStudent['EmergencyGuardianCellphone1'];
      $emergencyGuardianRelationship1 = $aStudent['EmergencyGuardianRelationShip1'];
      $emergencyGuardianName2 = $aStudent['EmergencyGuardianName2'];
      $emergencyGuardianCel2 = $aStudent['EmergencyGuardianCellphone2'];
      $emergencyGuardianRelationship2 = $aStudent['EmergencyGuardianRelationShip2'];
	    //
	    $hasAllergies = $aStudent['HasAllergies'];
	    $allergyDetails = $aStudent['AllergyDetails'];
	    $hasMedicalConditions = $aStudent['HasMedicalConditions'];
	    $hasMedicalConditionDetails = $aStudent['HasMedicalConditionDetails'];
	    $hasBehaviorIssues = $aStudent['HasBehaviorIssues'];
	    $hasBehaviorIssueDetails = $aStudent['HasBehaviorIssueDetails'];
	    $childInfoOthers = $aStudent['ChildInfoOthers'];


      $p = $a->readPreElementaryDetails($id);
      $pDetails = mysql_fetch_assoc($p);
      //
	    $guardianName1 = $pDetails['GuardianName1'];
      $guardianCel1 = $pDetails['GuardianCellphone1'];
      $guardianRelationship1 = $pDetails['GuardianRelationship1'];
      $guardianName2 = $pDetails['GuardianName2'];
      $guardianCel2 = $pDetails['GuardianCellphone2'];
      $guardianRelationship2 = $pDetails['GuardianRelationship2'];
      $parentExpectations = $pDetails['ParentExpectations'];
	  //
?>
<html>
  <title>School Enrollment :: Enrollment Form</title>
  <head>
    <link type="text/css" href="../../assets/styles.css" rel="stylesheet">
    <link type="text/css" href="../../assets/tabs.css" rel="stylesheet">
    <base href="../../" target="">
    <script type="text/javascript" src="assets/js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="../../assets/js/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" src="../../assets/js/jquery.ui.tabs.js"></script>
    <script type="text/javascript">
      $(document).ready(function()
      {
      	//When page loads...
      	//$('.enrolment-form').hide();
        $('#enrolment-status-pre,#enrolment-status-elem').attr('checked', false);
      	$(".tab_content").hide(); //Hide all content
      	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
      	$(".tab_content:first").show(); //Show first tab content
        //On Open Enrolment
        $('#enrolment-status-pre').click(function()
        {
          $('#prelem').slideToggle();
        });
        $('#enrolment-status-elem').click(function()
        {
          $('#elem').slideToggle();
        });
      	$("ul.tabs li").click(function()
      	{
      		$("ul.tabs li").removeClass("active"); //Remove any "active" class
      		$(this).addClass("active"); //Add "active" class to selected tab
      		$(".tab_content").hide(); //Hide all tab content
      		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
      		$(activeTab).fadeIn(); //Fade in the active ID content
      		return false;
      	});
      });

    </script>
  </head>
  <body>
    <div class="admin-container">
      <?php
         require_once '../commons.php';
         renderAdminNav();
       ?>
    </div>
    <div class="container">
      <ul class="tabs">
          <li><a href="#tab1" class="prev-next">Pre-Elementary</a></li>
      </ul>
      <div class="tab_container">
          <div id="tab1" class="tab_content">
              <!--Content-->
              <div class="open-enrolment"><input type="radio" name="enrolment-status" id="enrolment-status-pre" />
                Show Enrollment Form</div>
              <div><a href="#">Input Student Grades</a></div>
             <?php if($message) {?><div align="center"><strong>STUDENT DETAILS SUCCESSFULLY UPDATED.</strong></div><?php } ?>
                <form name="enrolment-form" class="enrolment-form" id="prelem" method="post" action="">
                  <table cellpadding="0" align="center">
                    <tr>
                      <th>Enrolment Form</th>
                    </tr>
                    <tr>
                      <td><label for="student-id">Student ID:</td>
                      <td><input type="text" name="student-id" value="<?php echo $id;?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="school-year">School Year:</label></td>
                      <td><input type="text" name="school-year" value="<?php echo $year?>" /></td>
                      <td colspan="2">
                        <label for="grade-level">Choose a level: </label>
                        <select name="grade-level">
                          <?php
                           while($rows=mysql_fetch_assoc($yearLevelPreElem))
                            {
                              $content = "";
                              $content.='<option value="'.$rows['YearLevelId'].'"';
                              //
                              if($rows['YearLevelId'] == $gradeLevel)
                                $content.='selected';
                              //
                              $content.='>'.$rows['YearLevelDescription'].'</option>';
                              echo $content;

                            }
                          ?>
                        </select>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="2">
                        <input type="radio" name="status" value="New" <?php if($status == 'New') echo 'checked'?> />New Student
                        <input type="radio" name="status" value="Old" <?php if($status == 'Old') echo 'checked'?>/>Old Student
                      </td>
                    </tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr>
                      <th colspan="2">Child's Details</th>
                    </tr>
                    <tr>
                      <td><label for="name">Student's Name: </label></td>
                      <td><input type="text" name="name" value="<?php echo $name; ?>" /></td>
                      <td><label for="birth-date">Birth Date: </label></td>
                      <td><input type="text" name="birth-date" value="<?php echo $birthDate; ?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="nickname">Nickname: </label></td>
                      <td><input type="text" name="nickname" value="<?php echo $nickname; ?>" /></td>
                      <td><label for="age">Age:</label></td>
                      <td><input type="text" name="age" value="<?php echo $age; ?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="home-number">Home Phone Number: </label></td>
                      <td><input type="text" name="home-number" value="<?php echo $phoneNum;?>"/></td>
                      <td><label for="address">Address:</label></td>
                      <td><input type="text" name="address" value="<?php echo $addr?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="religion">Religion:</label></td>
                      <td><input type="text" name="religion" value="<?php echo $religion ?>" /></td>
                      <td><label for="nationality">Nationality:</label></td>
                      <td><input type="text" name="nationality" value="<?php echo $nationality ?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="sex">Sex: </label></td>
                      <td>
                        <input type="radio" name="sex" value="Male" <?php if($gender == 'Male') echo 'checked' ?> />Male
                        <input type="radio" name="sex" value="Female" <?php if($gender == 'Female') echo 'checked' ?>/>Female
                      </td>
                    </tr>
                    <tr>
                      <td><label for="school-attended">School attended <br />(if transferee): </label></td>
                      <td><input type="text" name="school-attended" value="<?php echo $schoolAttended?>"/></td>
                      <td><label for="school-year-attended">SY: </label></td>
                      <td><input type="text" name="school-year-attended" value="<?php echo $schoolAttendedYr?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="lives-with">Student primarily lives with: </label></td>
                      <td>
                        <input type="radio" name="lives-with" value="Both Parents" <?php if($livesWith == 'Both Parents') echo 'checked'?>/>Both Parents<br />
                        <input type="radio" name="lives-with" value="Mother only" <?php if($livesWith == 'Mother only') echo 'checked'?> />Mother only<br />
                        <input type="radio" name="lives-with" value="Father only" <?php if($livesWith == 'Father only') echo 'checked'?> />Father only <br />
                        <input type="radio" name="lives-with" value="Other" <?php if($livesWith == 'Other') echo 'checked'?> />Other <br />
                        <label for="lives-with-specify">Specify</label><input type="text" name="lives-with-specify" value="<?php echo $livesWithSpecify?>" />
                      </td>
                    </tr>
                    <tr>
                      <th colspan="2">Parent's/Carer's Details</th>
                    </tr>
                    <tr>
                      <td><label for="fathers-name">Father's Name: </label></td>
                      <td><input type="text" name="fathers-name" value="<?php echo $father?>"/></td>
                      <td><label for="fathers-cellphone">Cellphone No.</label></td>
                      <td><input type="text" name="fathers-cellphone" value="<?php echo $fathersCel?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="fathers-occupation">Occupation: </label></td>
                      <td><input type="text" name="fathers-occupation" value="<?php echo $fathersOccupation?>"/></td>
                      <td><label for="fathers-office-number">Office Phone No.</label></td>
                      <td><input type="text" name="fathers-office-number" value="<?php echo $fathersOfficePhone?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="mothers-name">Mother's Name:</label></td>
                      <td><input type="text" name="mothers-name" value="<?php echo $mother?>"/></td>
                      <td><label for="mothers-cellphone">Cellphone No.</label></td>
                      <td><input type="text" name="mothers-cellphone" value="<?php echo $mothersCel?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="mothers-occupation">Occupation: </label></td>
                      <td><input type="text" name="mothers-occupation" value="<?php echo $mothersOccupation?>"/></td>
                      <td><label for="mothers-office-number">Office Phone No.</label></td>
                      <td><input type="text" name="mothers-office-number" value="<?php echo $mothersOfficePhone?>" /></td>
                    </tr>
                    <tr>
                      <td colspan="4"><p>Who will pick up the child from classes? Please list names and mobile phone numbers.</p></td>
                    </tr>
                    <tr>
                      <td><label for="guardian-name[]">1. Name:</label></td>
                      <td><input type="text" name="guardian-name[]" value="<?php echo $guardianName1?>" /></td>
                      <td><label for="guardian-cellphone[]">Cellphone No.</label></td>
                      <td><input type="text" name="guardian-cellphone[]" value="<?php echo $guardianCel1?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="guardian-relationship[]">Relationship to child:</label></td>
                      <td><input type="text" name="guardian-relationship[]" value="<?php echo $guardianRelationship1?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="guardian-name[]">2. Name:</label></td>
                      <td><input type="text" name="guardian-name[]" value="<?php echo $guardianName2?>"/></td>
                      <td><label for="guardian-cellphone[]">Cellphone No.</label></td>
                      <td><input type="text" name="guardian-cellphone[]" value="<?php echo $guardianCel2?>" /></td>
                    </tr>
                    <tr>
                      <td><label for="guardian-relationship[]">Relationship to child:</label></td>
                      <td><input type="text" name="guardian-relationship[]" value="<?php echo $guardianRelationship2?>"/></td>
                    </tr>
                    <tr>
                      <td colspan="4">
                        <h3><strong>EMERGENCY CONTACTS</strong></h3><br />
                        <em>The emergency contact person must be somebody other than the parents.</em>
                      </td>
                    </tr>
                    <tr>
                      <td><label for="emergency-guardian-name[]">1. Name:</label></td>
                      <td><input type="text" name="emergency-guardian-name[]" value="<?php echo $emergencyGuardianName1?>"/></td>
                      <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
                      <td><input type="text" name="emergency-guardian-cellphone[]" value="<?php echo $emergencyGuardianCel1?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
                      <td><input type="text" name="emergency-guardian-relationship[]" value="<?php echo $emergencyGuardianRelationship1?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="emergency-guardian-name[]">2. Name:</label></td>
                      <td><input type="text" name="emergency-guardian-name[]" value="<?php echo $emergencyGuardianName2?>"/></td>
                      <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
                      <td><input type="text" name="emergency-guardian-cellphone[]" value="<?php echo $emergencyGuardianCel2?>"/></td>
                    </tr>
                    <tr>
                      <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
                      <td><input type="text" name="emergency-guardian-relationship[]" value="<?php echo $emergencyGuardianRelationship2?>"/></td>
                    </tr>
                    <tr>
                      <td colspan="4"><h3><strong>GENERAL INFORMATION ABOUT YOUR CHILD</strong></h3></td>
                    </tr>
                    <tr>
                      <td colspan="2"><label for="child-allergies">Does your child have any allergies?</label></td>
                      <td>
                        <input type="radio" name="has-allergies" value="Yes" <?php if($hasAllergies == 'Yes') echo 'checked'?>/>Yes
                        <input type="radio" name="has-allergies" value="No"  <?php if($hasAllergies == 'No') echo 'checked'?>/>No
                      </td>
                    </tr>
                    <tr>
                      <td colspan="4"><p>If YES, please provide a detailed explanation of signs,symptoms and treatment needed.</p></td>
                    </tr>
                    <tr><td colspan="3"><textarea name="allergy-details" cols="40" rows="10"><?php echo $allergyDetails?></textarea></td>
                    </tr>
                    <tr>
                      <td colspan="2"><label for="child-medical-condition">Does your child have any medical condition/impairment/disability that you feel we need to know about?</label></td>
                      <td>
                        <input type="radio" name="has-medical-conditions" value="Yes" <?php if($hasMedicalConditions == 'Yes') echo 'checked'?>/>Yes
                        <input type="radio" name="has-medical-conditions" value="No"  <?php if($hasMedicalConditions == 'No') echo 'checked'?>/>No
                      </td>
                    </tr>
                    <tr>
                      <td colspan="4"><p>If YES - please provide a detailed explanation of what it is for and if there are any details our staff should know in order to provide care for your child and special understanding where needed.</p></td>
                    </tr>
                    <tr><td colspan="3"><textarea name="has-medical-condition-details" cols="40" rows="10"><?php echo $hasMedicalConditions?></textarea></td></tr>
                    <tr>
                      <td colspan="2"><label for="child-behavior-issues">Does your child have behavior management issues?</label><br />
                       <em> (Example - ADHD, fears or phobias, non-responsive, uncooperative etc.)</em>
                        </td>
                      <td>
                        <input type="radio" name="has-behavior-issues"  <?php if($hasBehaviorIssues == 'Yes') echo 'checked'?>value="Yes"/>Yes
                        <input type="radio" name="has-behavior-issues" value="No"  <?php if($hasBehaviorIssues == 'No') echo 'checked'?> />No
                      </td>
                    </tr>
                    <tr>
                      <td colspan="4"><p>If YES - please specify what medical condition, who it was diagnosed by, how it affects your child and management plans are in place including medication.</p></td>
                    </tr>
                    <tr><td colspan="3"><textarea name="has-behavior-issues-details" cols="40" rows="10"><?php echo $hasBehaviorIssueDetails ?></textarea></td></tr>
                    <tr>
                      <td colspan="4"><p>What other information(s) regarding your child that you feel our staff should be aware of?</p></td>
                    </tr>
                    <tr>
                      <td colspan="3"><textarea name="child-info-others" rows="10" cols="40"><?php echo $childInfoOthers?></textarea></td>
                    </tr>
                    <tr>
                      <td colspan="4"><p>What are you expecting your child will gain from attending Preschool?</p></td>
                    </tr>
                    <tr>
                      <td colspan="3"><textarea name="parent-expectations" rows="10" cols="40"><?php echo $parentExpectations?></textarea></td>
                    </tr>
                    <tr>
                      <td><input type="submit" name="pre-elem-form" value="Save Form Details" /></td>
                    </tr>
                  </table>
                </form>
          </div>
          <a id="prev-next" href="<?php echo PathHelper::getBaseUrl().'/Views/Admin/input_fees.php?id='.$id?>">Next Step &rarr;</a>
      </div><!--end of tab container -->
    </div><!--end of container -->
  </body>
</html>
